#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;

int minSleep(const vector<int>nums1,const vector<int>nums2,int n) {
	vector<vector<int>> dp;
	for (int i = 0; i < n + 1; ++i) {
		dp.emplace_back(3, INT32_MAX);
	}
	for (int i = 0; i < n; ++i) {
		if (i != 0) {
			dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]);
			dp[i][0] = min(dp[i][0], dp[i - 1][2]);

			if (nums1[i] == 1)
				dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]);
			if (nums2[i] == 1)
				dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]);
		}
		else {
			if (nums1[i] == 1)
				dp[i][1] = 0;
			if (nums2[i] == 1)
				dp[i][2] = 0;
		}
		if (dp[i][0] == INT32_MAX)
			dp[i][0] = 0;
		dp[i][0] += 1;
	}
	return min(dp[n - 1][0], min(dp[n - 1][1], dp[n - 1][2]));

}

//int main() {
//	int n;
//	cin >> n;
//	vector<int>nums1(n);
//	vector<int>nums2(n);
//	for (int i = 0; i < n; ++i) 
//		cin >> nums1[i];
//	for (int i = 0; i < n; ++i)
//		cin >> nums2[i];
//	cout << minSleep(nums1, nums2,n) << endl;
//}